/*
 * Created by CZJ on July 31, 2019.
 * @description 复制到黏贴版组件
 */
import React, { memo } from 'react';
import { Text, StyleSheet, TouchableOpacity, Clipboard } from 'react-native';
import _ from 'lodash';
import { adapt } from '~/utils/ScreenAdapter';
import Toast from '../Toast';

/*
 * @param data { String } 要复制的文字
 */
const ClipboardItem = memo(props => {
  let str = _.get(props, 'data') || '';
  return (
    <TouchableOpacity
      onPress={() => {
        Clipboard.setString(str);
        Toast.show('复制成功');
      }}
      style={styles.container}
    >
      <Text style={styles.text}>复制</Text>
    </TouchableOpacity>
  );
});

export default ClipboardItem;

const styles = StyleSheet.create({
  container: {
    width: adapt(48),
    height: adapt(24),
    borderColor: 'rgba(0, 0, 0, .32)',
    borderWidth: adapt(1),
    justifyContent: 'center',
    alignItems: 'center',
    borderRadius: adapt(2),
  },
  text: {
    color: 'rgba(0, 0, 0, .84)',
    lineHeight: adapt(20),
  },
});
